package com.scsj.supermarket.customview;

import android.graphics.Rect;
import android.support.v7.widget.RecyclerView;
import android.view.View;

/**
 * 横向滑动-间距
 */
public class DecorationSpacesHorizontal extends RecyclerView.ItemDecoration {

    private int space;

    public DecorationSpacesHorizontal(int space) {
        this.space=space;
    }

    @Override
    public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {

        outRect.bottom=space;
        outRect.top = space;
        // Add margin only for the first item to avoid double space between items
        if (parent.getChildLayoutPosition(view) == 0) {
            outRect.left=space;
            outRect.right=space;
        } else {
            outRect.right=space;
        }
    }
}